<%-- 
    Document   : CreateCar
    Created on : Nov 1, 2011, 11:35:02 PM
    Author     : Mr-aUgust
--%>

<%@page pageEncoding="UTF-8"%>
<%@ page language="java" import="javazoom.upload.*,java.util.*" %>
<%@ page session="true" import="java.util.Collection, DAL.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<%
        session.removeAttribute("status");
        session.removeAttribute("statusH");
        String im="";
        try{
        if (MultipartFormDataRequest.isMultipartFormData(request))
                      {
                         MultipartFormDataRequest mrequest = new MultipartFormDataRequest(request);
                         UploadBean upBean=new UploadBean();
                         upBean.setFolderstore(getServletContext().getRealPath("/") + "images\\car");
                         String todo = null;
                         if (mrequest != null) todo = mrequest.getParameter("todo");
                             if ( (todo != null) && (todo.equalsIgnoreCase("upload")) )
                             {
                                Hashtable files = mrequest.getFiles();
                                if ( (files != null) && (!files.isEmpty()) )
                                {
                                    UploadFile file = (UploadFile) files.get("uploadfile");
                                    if (file != null) //out.println("<li>Form field : uploadfile"+"<BR> Uploaded file : "+file.getFileName()+" ("+file.getFileSize()+" bytes)"+"<BR> Content Type : "+file.getContentType());
                                    // Uses the bean now to store specified by jsp:setProperty at the top.
                                        im="images/car/"+file.getFileName();
                                    upBean.store(mrequest, "uploadfile");
                                  //  out.println("<li> uploaded files success");
                                  //  out.println(getServletContext().getRealPath("/")+ "images\\car");
                                }
                                else
                                {
                                  out.println("<li>No uploaded files");
                                }
                             }
                   else out.println("<BR> todo="+todo);
                  }
            }catch (Exception ex){}
 %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>East2West Tours and Travels</title>
        <link rel="stylesheet" href="../WebContent/css/jquery.wysiwyg.css" type="text/css" />

        <link rel="stylesheet" href="examples.css" type="text/css" />
        <script src="../js/jqueryvalidate.js" type="text/javascript"></script>
        <script src="../js/jquery.validate.js" type="text/javascript"></script>
        <script src="../js/gen_validatorv4.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(document).ready(function() {
            $("#FormUpload").validate
                ({
                    rules:{
                        uploadfile:{ required: true}
                    },
                    messages: {
                        uploadfile:{required:"*"}   
                        }            
                });   
                
            });
            $(document).ready(function() {
            $("#FormInfoUpload").validate
                ({
                    rules:{
                        nameimage:{required: true},
                        carname:{ required: true},
                        seating:{required: true,digits: true},
                        driver:{required: true,digits: true},
                        PriceDate:{required: true},
                        PriceHour:{required: true},
                        Pricekilomet:{required: true}
                    },
                    messages: {
                           nameimage:{required: "Please choose a image upload."},
                           carname:{ required: "*"},
                           seating:{required: "*",digits: "Please enter only digits"},
                           driver:{required: "*",digits: "Please enter only digits"},
                           PriceDate:{required: "*"},
                           PriceHour:{required: "*"},
                           Pricekilomet:{required: "*"}
                    }            
                });   
                
            });
         </script>
       <style type="text/css">
            #khuncreate
            {
                margin-left:auto;
                margin-right:auto;
                width:600px;
                height:730px;
                background-color:#f0f3ec;
                margin-top:20px;
            }
            table
            {
                margin-left:auto;
                margin-right:auto;
            }
            .font
            {
                font-family:"Times New Roman", Times, serif;
                font-size:x-large;
                font-weight:bold;
                width:200px;
                height:30px;
                margin-left:auto;
                margin-right:auto;
                color:#0707e7;
            }
            #size
            {
            width:110px;
            }
        </style>
    </head>
    <body>
        <div id="khuncreate">
        <div class="font">Create Car</div> 
            <form action="management.jsp?page=CreateCar" method="post" name="FormUpload" id="FormUpload" enctype="multipart/form-data">
                <table border="0" width="500px">
                    <tr>
                        <td colspan="2" height="20px"></td>
                    </tr>
                   <tr>
                    <td>Choose Image:</td>
                    <td align="left" style="color:red;">
                            <input type="file" name="uploadfile" id="uploadfile" size="25">
                            <input type="hidden" name="todo" value="upload">
                            <input type="submit" name="Submit" value="Upload">  
                    </td>
                    <tr>
                        <td colspan="2" align="center">
                            <div style="color:red;" id="FormUpload_uploadfile_errorloc" class="error_strings"></div>
                        </td>
                    </tr>
                   
                </table>
            </form>
           
            <form action="../ControllerCar" method="post" name="FormInfoUpload" id="FormInfoUpload" >
               <table border="0" width="500px">
                <tr>
                    <td></td>
                    <td style="color:red;">
                       <% if(im !="")
                        {
                       %>
                            <img src="../<%=im%>"  width="100px" height="100px" />
                            <input type="hidden" name="image" value="<%=im%>" /> 
                        <%
                        }
                        %>
                        <input type="hidden" name="nameimage" value="<%=im%>" />
                    </td>
                </tr>
                <tr>
                    <td>Car Name:</td>
                    <td style="color:red;"><input type="text" name="carname" maxlength="90" size="25"/></td>
                </tr>
                <tr>
                    <td>Seating:</td>
                    <td style="color:red;"><input type="text" name="seating" maxlength="3" size="25"/></td>
                </tr>
                <tr>
                    <td>Air_conditioner:</td>                        
                    <td>
                        <input type="radio" name="conditioner" value="Yes" checked="true" />Yes
                        <input type="radio" name="conditioner" value="No"  />No
                     </td>
                </tr>
                <tr>
                    <td>Quantity:</td>                        
                    <td style="color:red;">
                        <input type="text" name="driver" maxlength="4" size="25"/>
                     </td>
                </tr>
                <tr>
                    <td>Price/date:</td>
                    <td style="color:red;"><input type="text" name="PriceDate" maxlength="15" size="25"/></td>
                </tr>
                <tr>
                    <td>Price/hour:</td>
                    <td style="color:red;"><input type="text" name="PriceHour" maxlength="15" size="25"/></td>
                </tr>
                <tr>
                    <td>Price/km:</td>
                    <td style="color:red;"><input type="text" name="Pricekilomet" maxlength="15" size="25"/></td>
                </tr>
                <tr>
                    <td>Car Type:</td>
                    <td>
                        <select name="CarType" id="CarType">
                            <option value="0">-- Choose Type --</option>
                            <option value="Small Size">Small Size</option>
                            <option value="Full Size">Full Size</option>
                            <option value="Luxury">Luxury</option>
                            <option value="Minivan">Minivan</option>
                        </select>
                        <div style="color:red;" id='FormInfoUpload_CarType_errorloc' class="error_strings"></div>
                    </td>
                </tr>
                <%
                 ModelCarBean mc=new ModelCarBean();
                 Collection collec=mc.ListModelCar();
                 request.setAttribute("mcar",collec);
                %>
                <tr>
                    <td>Model Car</td>
                    <td>
                        <select name="ModelCar" id="ModelCar" >
                        <option value="0"  >-- choose Model --</option>  
                        <c:forEach items="${mcar}" var="mocar">                        
                            <option value="${mocar.modelID}">${mocar.modelName}</option>                       
                        </c:forEach>
                        </select>
                        <div style="color:red;" id='FormInfoUpload_ModelCar_errorloc' class="error_strings"></div>
                    </td>
                </tr>
                <tr>
                    <td>Desciption:</td>
                    <td style="color:red;"><textarea name="wysiwyg" id="wysiwyg" rows="10" cols="40"></textarea></td>
                </tr>
                <tr>
                    <td colspan="2" height="20px"></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="submit" id="size" name="create" value="Create" /><input type="reset" id="size" value="Reset" /></td>
                </tr>
        </table>     
        </div>
        <script type="text/javascript" src="../WebContent/jquery/jquery.wysiwyg.js"></script>
            <script type="text/javascript">
            $(function()
            {
                $('#wysiwyg').wysiwyg();
            });
            
            </script>
         <script type="text/javascript">
             
            var frmuploadvalidator  = new Validator("FormUpload");
            frmuploadvalidator.EnableOnPageErrorDisplay();
            frmuploadvalidator.EnableMsgsTogether(); 
            frmuploadvalidator.addValidation("uploadfile","file_extn=jpg;gif;png","Allowed files types are: jpg;gif;png");
            
            var frmvalidator  = new Validator("FormInfoUpload");
            frmvalidator.EnableOnPageErrorDisplay();
            frmvalidator.EnableMsgsTogether();          
            frmvalidator.addValidation("CarType","dontselect=0","Choose a car type ");
            frmvalidator.addValidation("ModelCar","dontselect=0","Choose a model car ");
        </script>
    </body>
</html>

